﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserInfoPage.aspx.cs" Inherits="Easy.Web.Pages.PrivilegePages.UserInfoPage" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head id="Head1" runat="server">
    <title></title>
    <link href="/_css/bootstrap.min.css" rel="stylesheet" />
    <link href="/_css/sort.css" rel="stylesheet" type="text/css" />
    <link href="/_css/common.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/_css/iconfont.css" />
    <script src="/_js/jquery-1.9.1.min.js"></script>
    <script src="/_js/bootstrap.min.js"></script>
    <script src="/_js/custom.js" type="text/javascript"></script>
    <script src="/_js/common.js"></script>
    <script src="/_js/json2.js" type="text/javascript"></script>
    <script src="/_js/bootstrap-datetimepicker.min.js"></script>
    <script src="/_js/Core.js"></script>
    <script src="/_js/Core.Lookup.js"></script>

    <style>	
        #loading{display:none; background:#c0c0c0;opacity: 0.5;height: 100%;width: 100%;position: fixed;z-index: 4;margin-top: 0px;top: 0px;}
        #loading-center{width: 100%;height: 100%;position: relative;}
        #loading-center-absolute {position: absolute;left: 50%;top: 50%;height: 150px;width: 150px;margin-top: -75px;margin-left: -75px;-moz-border-radius: 50% 50% 50% 50%;-webkit-border-radius: 50% 50% 50% 50%;border-radius: 50% 50% 50% 50%;}
        .object{width: 20px;height: 20px;background-color: #FFF;position: absolute;-moz-border-radius: 50% 50% 50% 50%;-webkit-border-radius: 50% 50% 50% 50%;border-radius: 50% 50% 50% 50%;-webkit-animation: animate 0.8s infinite;animation: animate 0.8s infinite;}
        #object_one {
	        top: 19px;
	        left: 19px;	
	        }
        #object_two {
	        top: 0px;
	        left: 65px; 
	        -webkit-animation-delay: 0.1s; 
            animation-delay: 0.1s;

	        }
        #object_three {
	        top: 19px;
	        left: 111px; 	
	        -webkit-animation-delay: 0.2s; 
            animation-delay: 0.2s; 

	        }
        #object_four {
	        top: 65px;
	        left: 130px; 
	        -webkit-animation-delay: 0.3s; 
            animation-delay: 0.3s; 
        }
        #object_five {
	        top: 111px;
	        left: 111px; 
	        -webkit-animation-delay: 0.4s; 
            animation-delay: 0.4s; 
        }
        #object_six {
	        top: 130px;
	        left: 65px;
	        -webkit-animation-delay: 0.5s; 
            animation-delay: 0.5s; 
        }
        #object_seven {
	        top: 111px;
	        left: 19px;
	        -webkit-animation-delay: 0.6s; 
            animation-delay: 0.6s; 
        }
        #object_eight {
	        top: 65px;
	        left: 0px;
	         -webkit-animation-delay: 0.7s; 
            animation-delay: 0.7s; 
        }


        @-webkit-keyframes animate {
 
          25% {
	        -ms-transform: scale(1.5); 
   	        -webkit-transform: scale(1.5);   
            transform: scale(1.5);  
	          }


          75% {
	        -ms-transform: scale(0); 
   	        -webkit-transform: scale(0);  
            transform: scale(0);  
	          }


        }

        @keyframes animate {
          50% {
	        -ms-transform: scale(1.5,1.5); 
   	        -webkit-transform: scale(1.5,1.5); 
            transform: scale(1.5,1.5); 
	          }
 
          100% {
	        -ms-transform: scale(1,1); 
   	        -webkit-transform: scale(1,1); 
            transform: scale(1,1); 
	          }
  
        }




    </style>

    <script type="text/javascript">
        var RoleIdList = [];
        $(document).ready(function () {

            var UserId = $("#UserId").val();
            if (UserId != "") {
                $("#btn_saveRole").hide();
                $("#BusinessUnitSelect").attr("disabled", "disabled");
                GetRolesByUIdList();
            } else {
                $("#hiddenrow").hide();
                $("#BusinessUnitName").hide();
                $("#btn_updateRole").hide();
               

            }
            //GetEnitityListForUser();
            GetBusiList();


            $("#owninguser_btn").click(function(){
                $("#btn_function").attr('onclick','btn_MigrateUserRecords()');
            });

            $("#owningbusinessunit_btn").click(function(){
                $("#btn_function").attr('onclick','changeBs()');
            });


        }
        );


        function GetRolesByUIdList() {
            $.ajax({
                url: "/Service/Privilege/GetRolesByUIdList.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: {
                    "UserId": $("#UserId").val()
                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                            + " <thead><tr><th>#</th><th>角色名称</th></tr></thead><tbody>";

                    for (var i = 0; i < data.Roles.length; i++) {

                        var item = data.Roles[i];
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                        + "<td  id=\"list" + (i + 1) + "\">" + item.Name + "</td>"

                                + "</tr>";

                        RoleIdList[i] = item.RoleId;

                        
                    }


                    SMShtml += "</tbody></table>";
                    $("#rolesList_div").html(SMShtml);
                    
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }
        function GetBusiList() {
            $.ajax({
                url: "/Service/Privilege/GetBusinessUnit.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                },
                success: function (data, textStatus) {

                    var SMShtml = "";                 
                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        SMShtml += "<option value='" + item.BusinessUnitId + "'>" + item.Name + "</option>";                
                    }
                    $("#BusinessUnitSelect").html(SMShtml);
                    $("#BusinessUnitSelect").val($("#BusinessUnitId").val());
                    //RelationEntity_change();
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }
      
        function btn_add() {
            var UserRole = {};
            UserRole["UserId"] = $("#UserId").val();
            var RoleClassList = [];
          
            $("[type='checkbox']:checked").each(function () {
                var RoleClass = {};
                RoleClass["RoleId"] = $(this).attr("id");
                RoleClassList.push(RoleClass);
                //alert($(this).attr("id"))
            }
                );
            UserRole["Roles"] = RoleClassList;
        
            $.ajax({
                url: "/Service/Privilege/UserRoleSetting.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                    "json": JSON.stringify(UserRole),
                    "optionUser": "05e3362c-860e-411c-a1dc-32330b61b632"

                },
                success: function (data, textStatus) {

                     alert("success");
                    if (data.Result == "0") {
                        location.href = "/Pages/PrivilegePages/UserInfoPage.aspx?Id=" + data.Remark;

                    } else {
                        alert(data.Remark);
                    }


                },
                error: function (data, textStatus) {
                    alert("错误");

                }

            });

        }

        function btn_update() {
            var add = {};
            add["Name"] = $("#Name").val();
            add["BusinessUnit"] = $("#BusinessUnitId").val();
            add["BusinessUnitName"] = $("#BusinessUnitName").val();
            add["UserId"] = $("#UserId").val();
            $.ajax({
                url: "/Service/Privilege/SystemUser.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                    "systemuser": JSON.stringify(add),
                    "optionType": 2,
                    "optionUser": "05e3362c-860e-411c-a1dc-32330b61b632"

                },
                success: function (data, textStatus) {

                    // alert("success");
                    if (data.Result == "0") {
                        location.href = "/Pages/PrivilegePages/UserInfoPage.aspx?Id=" + data.Remark;

                    } else {
                        alert(data.Remark);
                    }


                },
                error: function (data, textStatus) {
                    alert("错误");

                }

            });

        }

        function btn_return() {
            window.location = "UserListPage.aspx";
        }

        function getRoleList() {
            $.ajax({
                url: "/Service/Privilege/GetRoleList.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                },
                success: function (data, textStatus) {

                    var SMShtml = "<table class='table table-hover'>"
                            + " <thead><tr><th></th><th>#</th><th>角色名称</th><th>所属部门"
                                               + "  </th>"
                                               + "</tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {

                        var item = data[i];
                        var isChecked = "";
                        for (var j = 0; j < RoleIdList.length; j++) {
                            if (item.RoleId == RoleIdList[j]) {
                                isChecked = "checked='checked'";
                            }
                        }
                        SMShtml += "<tr  name='list' id=\"" + (i + 1) + "\">"
                            + "<td>" + "<input id=" + item.RoleId + " type='checkbox' " + isChecked + " />" + "</td>"
                        /*NO*/ + "<td>" + (i + 1) + "</td>"
                        + "<td  id=\"list" + (i + 1) + "\">" + item.Name + "</td>"
                        + "<td   id=\"list" + (i + 1) + "\">" + item.BusinessUnit + "</td>"
                       + "</tr>";


                    }


                    SMShtml += "</tbody></table>";
                    $("#roleListInModal_div").html(SMShtml);
                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }
        function btn_save() {
            var add = {};
            add["Name"] = $("#Name").val();
            add["BusinessUnit"] = $("#BusinessUnitSelect").val();
            add["BusinessUnitName"] = $("#BusinessUnitSelect option:selected").val();
            add["UserId"] = $("#UserId").val();
            $.ajax({
                url: "/Service/Privilege/SystemUser.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
                    "systemuser": JSON.stringify(add),
                    "optionType": 1,
                    "optionUser": "05e3362c-860e-411c-a1dc-32330b61b632"

                },
                success: function (data, textStatus) {

                    // alert("success");
                    if (data.Result == "0") {
                        location.href = "/Pages/PrivilegePages/UserInfoPage.aspx?Id=" + data.Remark;

                    } else {
                        alert(data.Remark);
                    }


                },
                error: function (data, textStatus) {
                    alert("错误");

                }

            });

        }

        function btn_MigrateUserRecords() {
            var SystemUserId = $("#UserId").val();
            core.Lookup.SelectedLookup();
            var ToWho = core.Lookup.Selected["oid"];
            //alert("UsetId:" + SystemUserId);
            //alert("ToWho:" + ToWho);
            //alert("value:" + core.Lookup.Selected["value"]);

            $.ajax({
                url: "/Service/Privilege/MigrateUserRecords.ashx",
                async: true,
                type: "post",
                dataType: "json",
                data:{
                    "SystemUserId": SystemUserId,
                    "ToWho":ToWho
                },
                beforeSend:function(){
                    $("#loading").show();
                },
                success: function (data, textStatus) {
                    //alert("success");
                    $("#loading").hide();
                },
                error: function (data, textStatus) {
                    alert("错误");
                }
            });
            
        }

   //zw
        function changeBs() {

            var Id = $("#UserId").val();
            core.Lookup.SelectedLookup();
            var NewId = core.Lookup.Selected["oid"];


            //   alert(Id);
            //  alert(NewId);


            $.ajax({
                url: "/Service/Privilege/ChangeBs.ashx",
                async: true,
                type: "post",
                dataType: "json",
                data: {

                    "UserId": Id,
                    "NewId": NewId
                },
                beforeSend: function () {

                    $('#loading').show();


                },

                success: function (data, textStatus) {

                    //           alert("修改成功");

                    window.location.reload();



                },
                error: function (data, textStatus) {
                    alert("ajax错误");

                }

            });

        }

//zw-end






    </script>
    <style>
        .page-header{margin:15px;}
        .page-header+.btn-primary{margin:0px 15px 10px 5px;}
        .panel-heading{padding:3px 15px;height:40px;line-height:34px;}
    </style>
</head>
<body>
    <div id="loading" style="position:fixed;">
        <div id="loading-center">
            <div id="loading-center-absolute">
                <div class="object" id="object_one"></div>
                <div class="object" id="object_two"></div>
                <div class="object" id="object_three"></div>
                <div class="object" id="object_four"></div>
                <div class="object" id="object_five"></div>
                <div class="object" id="object_six"></div>
                <div class="object" id="object_seven"></div>
                <div class="object" id="object_eight"></div>
            </div>
        </div>
    </div>

    <form id="form1" runat="server">
        <div class="">
            <div class="row">
                <div class="col-lg-12">
                    <input id="UserId" type="hidden" value="<%=user.UserId %>" />
                    <input id="BusinessUnitId" type="hidden" value="<%=user.BusinessUnit %>" />

                    <h1 class="page-header">用户信息</h1>
                    <button type='button' style="float: right" id='btn_back' class='btn btn-primary ng-binding'
                        onclick="btn_return()">
                        返回用户列表</button>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            用户基本信息
                            <button type='button' style="float: right" id='btn_updateRole' class='btn btn-primary ng-binding'
                                onclick="btn_update();">
                                修改</button>
                            <button type='button' style="float: right;" id='btn_saveRole' class='btn btn-primary ng-binding'
                                onclick="btn_save();">
                                保存</button>
                            <!--增加 更改用户部门，迁移用户记录按钮-->
                         
                            <button class="btn btn-primary ng-binding btn-lookup" style="float: right;margin-right:3px;" id="owninguser_btn" fieldid="owninguser" etn="SystemUser" type="button">
                                迁移用户记录</button>
                            <!--<button type='button' onclick='keep();' class='btn btn-primary ng-binding' data-toggle='modal'data-target='#myModal'>更改</button>-->
                            <button class="btn btn-primary ng-binding btn-lookup" style="float: right;margin-right:3px;" id="owningbusinessunit_btn" fieldid="owningbusinessunit" etn="BusinessUnit" type="button">
                                更改业务部门</button>

                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="Name">
                                    用户名称</label>
                                <input type="text" class="form-control" id="Name" value="<%= user.Name %>" />
                            </div>
                            <div class="form-group">
                                <label for="BusinessUnitName">
                                    部门</label>
                                <%-- <input type="text" disabled="disabled" class="form-control" id="BusinessUnitName" value="<%= user.BusinessUnitName %>" />--%>
                                <div class="form-group" id="BusinessUnitDiv">
                                    <select class="form-control" id="BusinessUnitSelect">
                                    </select>
                                </div>
                            </div>

                           

                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <div id="hiddenrow" class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            角色
                            
                                <button type='button' style="float: right;" id='btn_addRole' class='btn btn-primary ng-binding' data-toggle="modal" data-target="#myModal2" onclick="getRoleList()">
                                    管理</button>
                            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog"
                                aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="" true>&times;</span> </button>
                                            <h4 class="modal-title" id="myModalLabel">角色列表</h4>
                                        </div>
                                        <div class="modal-body">
                                            <div id="roleListInModal_div">
                                            </div>

                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-primary ng-binding btn-lookup" onclick="btn_add()">确定</button>
                                        </div>
                                    </div>
                                </div>

                            </div>



                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="table-responsive">
                                <div id="rolesList_div">
                                </div>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
        </div>

        <div id="LookupModal" class="modal fade in" etn="" fieldid="">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">搜索:<span id="modal-title-etn"></span></h4>
                        </div>
                        <div class="modal-body" style="max-height: 500px; overflow: hidden">
                            <div class="input-group">
                                <input type="text" id="txt_lookupsearchValue" class="form-control" placeholder="Search for..." />
                                <span class="input-group-btn">
                                    <button class="btn btn-primary ng-binding" type="button" onclick="core.Lookup.Search();">
                                        搜索</button>
                                </span>
                            </div>
                            <div id="LookupListContainer">
                            <div id="LookupListContainer-title">
                            <table id="" class="table table-condensed table-hover">
                                <colgroup></colgroup>
                                <thead></thead>                                
                            </table>
                            </div>
                            <div id="LookupListContainer-body">
                            <table id="" class="table table-condensed table-hover">
                                <colgroup></colgroup>
                                <tbody></tbody>
                            </table>
                            </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <nav id="ListPageing" style="float: left;">
                                <ul class="pagination" style="margin: 0;">
                                    <li><a href="javascript:void(0);" id="pageFirst" aria-label="Firset" onclick='core.Lookup.FirstPage();'><span aria-hidden="true">&laquo;</span>
                                    </a></li>
                                    <li><a href="javascript:void(0);" id="pagePrevious" aria-label="Previous" onclick='core.Lookup.PrePage();'><span aria-hidden="true">&lsaquo;</span>
                                    </a></li>
                                    <li><span id="pageInfo">1\50</span></li>
                                    <li><a href="javascript:void(0);" id="pageNext" aria-label="Next" onclick='core.Lookup.NextPage();'><span aria-hidden="true">&rsaquo;</span>
                                    </a></li>
                                    <li><a href="javascript:void(0);" id="pageLast" aria-label="Last" onclick='core.Lookup.LastPage();'><span aria-hidden="true">&raquo;</span>
                                    </a></li>
                                </ul>
                            </nav>
                            <button type="button" id="btn_function" class="btn btn-primary ng-binding" onclick="core.Lookup.SelectedLookup();"
                                data-dismiss="modal">
                                OK</button>
                            <!--
                            <button type="button" class="btn btn-primary ng-binding" onclick="core.Lookup.SelectedLookup();"
                                data-dismiss="modal">
                                OK</button>
                            -->
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>


    </form>


</body>
</html>
